// 开发环境配置的
// 创建本地服务器，及实时监听css及js文件的改变

var path = require('path')
var webpack = require('webpack');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var AssetsPlugin = require('assets-webpack-plugin');
module.exports = {
    devtool: 'cheap-eval-source-map',
    entry: [
        'webpack-dev-server/client?http://127.0.0.1:8080',
        'webpack/hot/dev-server',
        './src/js/index',
        './src/js/a',
        './src/less/main.less'
    ],
    output: {
        path: path.join(__dirname, 'build'),
        filename: '/js/[name].js'
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new HtmlwebpackPlugin({
            title: 'Hello World app',
            filename: 'html/index_cfg.html',
            template: 'src/html/index_cfg.html',
            inject: true,
            hash: true
        }),
        new ExtractTextPlugin("css/style_cfg.css"),
        new AssetsPlugin({
            filename: 'build/html/webpack.assets.js',
            processOutput: function(assets) {
                return 'window.WEBPACK_ASSETS = ' + JSON.stringify(assets);
            }
        })
    ],
    module: {
        loaders: [
            //.css 文件使用 style-loader 和 css-loader 来处理
            {
                test: /\.less$/,
                loader: ExtractTextPlugin.extract(
                    'css?sourceMap!' +
                    'less?sourceMap'
                )
            },

            {
                test: /\.js$/,
                loader: 'babel'
            }, {
                test: /.(png|jpg)$/,
                loader: 'url?limit=8192&name=images/[hash:8].[name].[ext]'
            }
        ]
    },
    devServer: {
        contentBase: './dist',
        hot: true
    }
}
